package dk.config;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import feign.RequestInterceptor;
import feign.RequestTemplate;

@Configuration
public class FeignConfiguration implements RequestInterceptor {

	 @Override
	    public void apply(RequestTemplate template) {
	        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
	                .getRequestAttributes();
	        HttpServletRequest request = attributes.getRequest();
	        Enumeration<String> headerNames = request.getHeaderNames();
	        if (headerNames != null) {
	            while (headerNames.hasMoreElements()) {
	                String name = headerNames.nextElement();
	                String values = request.getHeader(name);
	                // 跳过 content-length
	                if (name.equals("content-length")){
	                    continue;
	                }
	                template.header(name, values);
	            }
	        } else {
	           
	        }
	    }
}